import time,requests
from flask import render_template, request
from application.views.api.callback import callback
from application.views.back import back
from application.views.course import course_data
from application.views.tocourse import tocourse
from create_app import CreateFlask
from application.views.user import user_blue
from application.views.viewscokit import socket

flask_obj = CreateFlask()
app = flask_obj.app

app.register_blueprint(user_blue, url_prefix='/user')
app.register_blueprint(back, url_prefix='/back')
app.register_blueprint(callback, url_prefix='/callback')
app.register_blueprint(course_data, url_prefix='/course')
app.register_blueprint(tocourse, url_prefix='/tcourse')

# # 监控
# @app.route('/', methods=['POST'])
# def index():
#     data = request.json
#     url = "https://oapi.dingtalk.com/robot/send?access_token=c42ae971590b607310e128b490a8aef9119c33929f48d944bf620ca9cf8c2271"
#     ret = requests.post(url, json={
#         "msgtype": "markdown",
#         "markdown": {
#             "title": "监控",
#             "text": f"""#### 监控通知 \n
# > cpu {data['cpu_info']}\n
# > 内存总量 {data['total_memory']}G\n
# > 已用内存 {int(data['used_memory'])}\n
# @17611406668"""
#         },
#         "at": {
#             "atMobiles": [
#                 "17611406668"
#             ],
#             "atUserIds": [
#                 "vqt_2ayf8q6bb"
#             ],
#             "isAtAll": False
#         }
#     })
#     print(ret.json())
#     return "ok"

@app.route('/', methods=['get'])
def index():
    return render_template('ws_index.html', async_mode='123')

@app.route('/player', methods=['GET'])
def Film_Play():
    return render_template('player.html', movie={'file': 'vip.mp4', 'title': '???'})

if __name__ == '__main__':
    print(app.url_map)
    # app.run(host='0.0.0.0', port=8000, threaded=True)
    socket.run(app, host='0.0.0.0', port=8000, debug=True)
